package org.example.demo21.iterator.iter;

import org.example.demo21.iterator.DrinkIterator;
import org.example.demo21.iterator.entity.MenuItem;

/**
 *
 * @author guocong
 * @since 2024/4/1 13:48
 */
public class DrinkShopIter implements DrinkIterator {

    MenuItem[] menuItems;
    int position = 0;

    public DrinkShopIter(MenuItem[] menuItems){
        this.menuItems = menuItems;
    }

    @Override
    public boolean hasNext() {
        return position <= menuItems.length - 1 && menuItems[position] != null;
    }

    @Override
    public Object next() {
        MenuItem menuItem = menuItems[position];
        position ++;
        return menuItem;
    }

}
